package com.lagou.edu.service.impl;

import com.lagou.edu.dao.AccountDao;
import com.lagou.edu.dao.ResumeDao;
import com.lagou.edu.pojo.Account;
import com.lagou.edu.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class AccountServiceImpl implements AccountService {


    @Autowired
    private AccountDao accountDao;

    @Override
    public List<Account> queryAccountList() throws Exception {

        return accountDao.findByJpql("1");
    }



    @Override
    @Transactional(readOnly=false)
    public void delteById(Long id) throws Exception {
        accountDao.deleteById(id);
     }

    @Override
    public boolean login(String username, String password, HttpServletRequest request) {
        List<Account> list = accountDao.findBySql(username,password);
        if (list ==null || list.size()<1) {
            return false;
        }
        request.getSession().setAttribute("user",list.get(0));
        return true;
    }


}
